package com.kevin.sharding.demo.dao;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * @version OrderDao.java v2.0
 * @description:
 * @author: wenze
 * @create: 2020/8/29 23:07
 **/
@Component
@Mapper
public interface OrderDao {

    @Insert("insert into t_order(price,user_id,status) values(#{price},#{userId},#{status})")
    int insertOrder(@Param("price") BigDecimal price, @Param("userId") Long userId, @Param("status") String status);

    @Select("<script>" +
            "select * from t_order where order_id in" +
            "<foreach collection='orderIds' item='id' open='(' close=')' separator=','>" +
            "#{id}" +
            "</foreach>" +
            "</script>")
    List<Map> selectOrderByIdList(@Param("orderIds") List<Long> orderIds);


    @Select("<script>" +
            "select * from t_order where order_id in" +
            "<foreach collection='orderIds' item='orderId' open='(' close=')' separator=','>" +
            "#{orderId}" +
            "</foreach>" +
            "and user_id = #{userId}" +
            "</script>"
    )
    List<Map> testSelectOrderUserIdAndIdList(@Param("userId") Long userId, @Param("orderIds") List<Long> orderIds);
}
